﻿using System;
using System.Text;

namespace FxWinSuper.Util
{
	public static class ObjectUtil
	{
		public static void AssertNotNull(params object[] objects)
		{
			if (objects == null)
			{
				throw new NullReferenceException("objects is null");
			}

			foreach (object obj in objects)
			{
				if (obj == null)
				{
					throw new NullReferenceException("objects has null");
				}
			}
		}

		public static void Let<T>(this T obj, Action<T> runAction)
		{
			runAction?.Invoke(obj);
		}

		public static bool EndsWith(this StringBuilder sb, string endStr)
		{
			char[] chars = endStr.ToCharArray();
			if (sb.Length < chars.Length)
			{
				return false;
			}

			for (int i = 0; i < chars.Length; i++)
			{
				if (chars[chars.Length - i - 1] != sb[sb.Length - i - 1])
				{
					return false;
				}
			}

			return true;
		}
	}
}
